Test Series - Data Structure

Test Number 37/115

Q: Which of the following is false?
A. Suffix array is always sorted
B. Suffix array is used in string matching problems
C. Suffix array is always unsorted
D. Suffix array contains all the suffixes of the given string
Solution: Suffix array is always sorted as it contains all the suffixes of a string in sorted order. Suffix arrays are used to solve problems related to string, like string matching problems.
Q: Suffix array of the string “statistics” is ____________
A. 2 8 7 4 9 0 5 1 6 3
B. 2 7 4 9 8 0 5 1 6 3
C. 2 4 9 0 5 7 8 1 6 3
D. 2 8 7 0 5 1 6 9 4 3
Solution: The suffix array of the string statistics will be:
2 atistics
8 cs
7 ics
4 istics
9 s
0 statistics
5 stics
1 tatistics
6 tics
3 tistics
In Suffix array, we only store the indices of suffixes. So, correct option is 2 8 7 4 9 0 5 1 6 3.
Q: Suffix array can be created by performing __________ traversal of a suffix tree.
A. breadth-first
B. level order
C. depth-first
D. either breadth-first or level order
Solution: A suffix tree is a trie, which contains all the suffixes of the given string as their keys and positions in the string as their values. So, we can construct a suffix array by performing the depth-first traversal of a suffix tree.
Q: Suffix array is space efficient and faster than the suffix tree.
A. True
B. Fasle
C. ...
D. ...
Solution: Suffix arrays are more space efficient than the suffix trees as they just store the original string and an array of integer. But working with suffix tree is faster than that of the suffix array.
Q: If comparison based sorting algorithm is used construct the suffix array, then what will be time required to construct the suffix array?
A. O(nlogn)
B. O(n2)
C. O(n2logn)
D. O(n2) + O(logn)
Solution: On average comparison based sorting algorithms require O(nlogn) comparisons. But comparing a suffix takes O(n). So, overall time to construct the suffix array will be O(nlogn) * O(n) = O(n2logn).
Q:  What will be the suffix array of the string “engineering”?
A. 2 3 8 4 9 1 7 5 0 6 10
B. 5 0 6 1 4 9 1 7 0 2 3 8
C. 5 0 6 10 2 4 9 1 7 3 8
D. 5 0 6 10 2 3 8 4 9 1 7
Solution: Correct choice is : 5 0 6 10 2 3 8 4 9 1 7.
Because the suffix array formed will be: 5 eering 0 engineering 6 ering 10 g 2 gineering 3 ineering 8 ing 4 neering 9 ng 1 ngineering 7 ring.
Q: LCP array and ______ is used to construct suffix tree.
A. Hash tree
B. Hash trie
C. Suffix array
D. Balanced tree
Solution: Suffix tree can be created using an LCP array and a suffix array. If we are given a string of length (n + 1) and its suffix array and LCP array, we can construct the suffix tree in linear time i.e in O(n) time.
Q: What is the time required to locate the occurrences of a pattern P of length m in a string of length n using suffix array?
A. O(nm)
B. O(n2)
C. O(mnlogn)
D. O(mlogn)
Solution: Suffix arrays are used to find the occurrences of a pattern in a string. Pattern of length m will require m characters to compare, so using suffix array we can find occurrences of a pattern in the string of length n in O(mlogn) time.
Q: Suffix array can be created in O(nlogn) time.
A. True
B. False
C. ...
D. ...
Solution: Suffix array can be constructed in O(n2logn) time using sorting algorithms but it is possible to build the suffix array in O(nlogn) time using prefix doubling.
Q: Which of the following is/are advantages suffix array one suffix tree?
I. Lesser space requirement
II. Improved cache locality
III. Easy construction in linear time
A. Only I
B. All I, II and III
C. Only I and III
D. Only II and III
Solution: Advantages of the suffix array over suffix tree are : (i) Lesser space requirement (ii) Improved cache locality and (iii) Simple algorithms to construct suffix arrays in linear time.

You Have Score    /10